package be.technofutur.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class HelloServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
		
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	//	doGet(request, response);		
		Date now = new Date();
		String username="";
		String dateStamp = new SimpleDateFormat("dd/MM/yyyy").format(now);
		String timeStamp = new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime());
		PrintWriter out = response.getWriter();
	  /*  username=request.getParameter("username");
		if(username==null || username.isEmpty()==true)
			response.sendRedirect("http://www.google.be/search?q="+request.getParameter("username"));*/
		out.println("<html><head><title>Hello Web SVN</title></head>");
		out.println("<body><h1>Hello "+request.getParameter("username")+"!</h1>");
		out.println("<p>Nous somme le "+dateStamp+"</p>");
		out.println("<p>Il est "+timeStamp+"</p>");
		out.println("<form method=\"POST\" action=\"/HelloWeb/Hello\">");
		out.println("<input type=\"text\" name=\"username\"></>");
		//response.sendRedirect("http://www.google.be/search?q="+request.getParameter("username"));
		//request.getRequestDispatcher(username).forward(request, response);
		out.println("<input type=\"submit\" value=\"go\"></>");
		out.println("</form></body></html>");
		
	
	}

}
